﻿using Navigant.Model.Custodians;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Navigant.Infrastructure.Cases;
using Navigant.Model.PreservationNotices;
using System;
using System.Configuration;
using Navigant.Model.Cases;

namespace Navigant.UnitTests
{
    
    
    /// <summary>
    ///This is a test class for CustodianTest and is intended
    ///to contain all CustodianTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CustodianTest
    {

        private Uri siteUri;
        private TestContext testContextInstance;

        public CustodianTest()
        {
            this.siteUri = new Uri(ConfigurationManager.AppSettings["testCaseSite"]);
        }

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Status
        ///</summary>
        [TestMethod()]
        public void CustodianStatusTest()
        {
            ICase parentCase = CaseService.GetCaseBy(this.siteUri);
            CustodianService service = new CustodianService(parentCase);
            Custodian target = service.FindAll()[0];
            PreservationNoticeStatus actual = target.Status;
            Assert.AreNotEqual(PreservationNoticeStatus.Reminded, actual);
            Assert.AreNotEqual(PreservationNoticeStatus.ReminderQueued, actual);
            if (string.IsNullOrEmpty(target.Email))
            {
                Assert.AreEqual(PreservationNoticeStatus.NoEmail, target.Status);
            }
        }

        [TestMethod()]
        public void CustodianCanReceiveMessagesTest()
        {
            ICase parentCase = CaseService.GetCaseBy(this.siteUri);
            Custodian custodian = new Custodian(parentCase, 
                new CustodianName("Timothy McCarthy"), "tmccart1@san.rr.com");
            Assert.IsTrue(custodian.CanReceiveMessages());
            if (parentCase.ClientPortal.DoNotSendToTerminatedCustodians)
            {
                custodian.SetExtendedProperty(parentCase.ClientPortal.CustodianTerminatedFieldName,
                    DateTime.Now.ToString());
                Assert.IsFalse(custodian.CanReceiveMessages());
            }
        }
    }
}
